package com.xhh.common.aliyun.util;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.google.gson.Gson;

/**
 * 短信发送工具类
 */
public class SMSUtils {

	/**
	 * 发送短信
	 * @param signName 签名
	 * @param templateCode 模板
	 * @param phoneNumbers 手机号
	 * @param param 参数
	 */
	public static void sendMessage(String signName, String templateCode,String phoneNumbers,String param){
		Config config = new Config()
				// 您的AccessKey ID
				.setAccessKeyId("LTAI5tLdeoWaF1JiWC511RxS")
				// 您的AccessKey Secret
				.setAccessKeySecret("gbZa6i967PV8Jr01CRCkCLxBMjkvuC");
		// 访问的域名
		config.endpoint = "dysmsapi.aliyuncs.com";

		Client client = null;
		try {
			client = new Client(config);
		} catch (Exception e) {
			e.printStackTrace();
		}

		SendSmsRequest request = new SendSmsRequest();
		request.setPhoneNumbers(phoneNumbers);
		request.setSignName(signName);
		request.setTemplateCode(templateCode);
//		request.setTemplateParam("{\"stuName\":\""+stuName+"\",\"ufmName\":\""+ufmName+"\"}");
		request.setTemplateParam(param);
		try {
			SendSmsResponse response = client.sendSms(request);
			System.out.println(new Gson().toJson(response.getBody()));
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

}
